package notepad;

import java.util.Scanner;

public class SecuredNotepad extends SimpleNotepad implements ISecuredNotepad
{

	private final String password;
	Scanner sc = new Scanner(System.in);
	SecuredNotepad(int numberOfPages, String password) 
	{
		super(numberOfPages);
		this.password = password;
	}
	
	@Override
	public boolean askForPassword() 
	{
		System.out.println("enter pass");
		return sc.next().equals(password);
	}
	@Override
	public void addSomeText(int pageNumber, String someText) 
	{
		if(askForPassword())
		{
			super.addSomeText(pageNumber, someText);
		}
	}

	@Override
	public void replaceText(int pageNumber, String someText) 
	{
		if(askForPassword())
		{
			if(validatePage(pageNumber))
			{
				pages[pageNumber - 1].deleteText();
				pages[pageNumber - 1].addSomeText(someText);
			}
		}
	}
	
	@Override
	public void deleteSomeText(Page selectedPage) 
	{
		if(askForPassword())
		{
			for (int i = 0; i < pages.length; i++) 
			{
				if(pages[i].equals(selectedPage))
				{
					selectedPage.deleteText();
				}		
			}
		}		
	}	
}
